// printRoom Mannamg
function printDataPayment(){
	var link = "/messagefolioService";
	var data = { func: "getMessageFolio"}
	simpleserviceSyn(link,data,messageSuccess);
}

function messageSuccess(data){
	var objArray = JSON.parse(data);
	var dateIn = new Date(getCurrentTabData().ResData.date);
	var nextDate = new Date(getCurrentTabData()["ResData"].date);
	var	datecheckOutSet = nextDate.addDate(1).toSystemFormat();
	var dateTo = new Date(datecheckOutSet);
	var formatDateIn = dateIn.getFormatedString();
	var formatDateTo = dateTo.getFormatedString();
	/// Guest
	var nameGuest = getCurrentTabData().guest[0].Name;
	var phoneGuest = getCurrentTabData().guest[0].phone;
	var idGuest = getCurrentTabData().guest[0].id;
	var addressLine1Guest = getCurrentTabData().guest[0].addressLine1;
	var addressLine2Guest = getCurrentTabData().guest[0].addressLine2;
	/// Room
	var rooType = getCurrentTabData().ResData.roomTypeName;
    var	roomName = getCurrentTabData().ResData.roomName;
    var priceRateName = getCurrentTabData().ResData.priceRateName;
    var adultRoom = "";
    var childRoom = "";
    var commaAdultChild = "";
    var sumPerson = 0;
    if(getCurrentTabData().ResData.adult!=0)
    	adultRoom = getCurrentTabData().ResData.adult+" Adults";
    if(getCurrentTabData().ResData.child!=0)
    	childRoom = getCurrentTabData().ResData.child+" Childs";
    if(getCurrentTabData().ResData.child!=0&&getCurrentTabData().ResData.adult!=0)
    	commaAdultChild = ","
    sumPerson = getCurrentTabData().ResData.adult+getCurrentTabData().ResData.child;
	/// Price
	var TotalBalance = toCurrencyString(getCurrentTabData().calBalance.TotalBalance);
	var otherCharge = toCurrencyString(getCurrentTabData().calBalance.otherCharge);
	var roomsTax = toCurrencyString(getCurrentTabData().calBalance.roomsTax);
	var roomdiscount = toCurrencyString(getCurrentTabData().calBalance.roomdiscount);
	var roomdiscountAcc = toCurrencyString(getCurrentTabData().calBalance.roomdiscountAcc);
	var payprice = toCurrencyString(getCurrentTabData().calBalance.payprice);
	var roomsTaxAcc = toCurrencyString(getCurrentTabData().calBalance.roomsTaxAcc);
	var TotalWithTax = 	toCurrencyString(getCurrentTabData().calBalance.TotalBalance+getCurrentTabData().calBalance.roomsTax);
	var Balance = toCurrencyString((getCurrentTabData().calBalance.TotalBalance+getCurrentTabData().calBalance.roomsTax)-getCurrentTabData().calBalance.payprice);
	///
	/// detail Room
	var dateDetailRoom = new Date(getCurrentTabData().ResData.date).getFormatedString();
    var description = getCurrentTabData().ResData.roomTypeName+" "+ 
	getCurrentTabData().ResData.roomName+"/"+
	new Date(getCurrentTabData().ResData.date).getFormatedDateAndMonthString()+ " - "+
	new Date(getCurrentTabData().ResData.date).addDate(getCurrentTabData().ResData.span).getFormatedDateAndMonthString()+"/"+
	getCurrentTabData().ResData.id;
	///
    /// payment
    var paymentPrint = "";
    var printPayment = getCurrentTabData().PaymentList;
    for(var i = 0;i<printPayment.length;i++){
    	paymentPrint += '<tr style="background-color:#F7F9A2">'+
    					"<td>"+new Date(printPayment[i].payDate).getFormatedString()+"</td>" +
				 		'<td><span>'+printPayment[i].description+'</span></td>'+
				 		'<td><span style="color:#3b69b3;">&nbsp;</span></td>'+
				 		'<td><span>&nbsp;</span></td>'+
				 		'<td><span style="float:right;">&nbsp;</span></td>'+
				 		'<td><span style="float:right;">0.00</span></td>'+
				 		'<td><span>&nbsp;</span></td>'+
				 		'<td><span style="float:right;">'+parseFloat(printPayment[i].amount).toFixed(currencyDecimalPlaces)+'</span></td>'+
				 		'</tr>';
    }
    /// charge
    var chargePrint = "";
    var refundPrint = "";
    var disPlayFolioStatus = "";
    var folioNumber = "";
    var chargeList = getCurrentTabData().ChargeList;
    sortIdPrint(chargeList);
    for(var i = 0;i<chargeList.length;i++){
    	if(!chargeList[i].isTemp){
    		var folioNumber="";
    		var q ="";
    		var rc="";
	    	if(chargeList[i].Qty != parseInt(0))
			{
				q=Qty+" "+chargeList[i].Qty+" ";
				rc=roomCharge+"/";
			}
	    	if(chargeList[i].FolioId !=0)
			{
				disPlayFolioStatus="PI";
				folioNumber = chargeList[i].FolioId;
			}
	    	if(chargeList[i].isRefund){
	    		refundPrint +=  '<tr style="background-color:#fbc9c8;">'+
						 		'<td>'+
						 		'<span>'+new Date(chargeList[i].chargeDate).getFormatedString()+'</span>'+
						 		'</td>'+
						 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeList[i].description+'</span></td>'+
						 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatus+" "+folioNumber+'</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'<td><span id=charge'+i+' charge="'+chargeList[i].chargeAmount+'">'+toCurrencyString(chargeList[i].chargeAmount,false)+'</span></td>'+
						 		'<td><span id=tax'+i+' tax="'+chargeList[i].tax+'" >'+toCurrencyString(chargeList[i].tax,false)+'</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'</tr>';
	    	}
    		chargePrint +=  '<tr class="border-top" id="'+chargeList[i].id+'">'+
					 		'<td>'+
					 		'<span>'+new Date(chargeList[i].chargeDate).getFormatedString()+'</span>'+
					 		'</td>'+
					 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeList[i].description+'</span></td>'+
					 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatus+" "+folioNumber+'</span></td>'+
					 		'<td><span>&nbsp;</span></td>'+
					 		'<td><span id=charge'+i+' charge="'+chargeList[i].chargeAmount+'">'+toCurrencyString(chargeList[i].chargeAmount,false)+'</span></td>'+
					 		'<td><span id=tax'+i+' tax="'+chargeList[i].tax+'" >'+toCurrencyString(chargeList[i].tax,false)+'</span></td>'+
					 		'<td><span>&nbsp;</span></td>'+
					 		'<td><span>&nbsp;</span></td>'+
					 		'</tr>'+refundPrint;
    		refundPrint = "";
    	}
    }
   var textSumStatement =   '<tr style="background-color:#DDD">'+
						    '<td colspan="4">'+
						    '<span id="payment-account-date" style="padding-left:200px">รวม'+
						    '</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-cost" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.chargePriceAcc,false)+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-tax" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.roomsTaxAcc,false)+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-currency" style="float:right;">'+SharedData.General.defaultCurrency.symbol+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-payment" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.payprice,false)+'</span>'+
						    '</td>'+
						    '</tr>';
    ///
	var reservation = "";
	if(getCurrentTabData().type=="Group")
		reservation = "Res ID:"+getCurrentTabData().resId;
	else
		reservation = getCurrentTabData().resId;
	myWindow=window.open('','','width=783,height=722');
	var headHtml = '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' +
				    '<title></title>' +
				    '<script src="js/jquery-1.8.3.min.js"></script>'+
				    '<link href="css/print/print.css" rel="stylesheet" type="text/css">' +
				    '</head><body>';
	var hotel = '<table align="center" border="0" cellpadding="10" cellspacing="0" width="100%">' +
		    '<tbody>' +
		    '<tr>' +
		    '<td width="65%">' +
		    '<img src="https://s3.amazonaws.com/livestaygriddata/product-images/hotels/logo/logo08042013072057140130407.jpeg" width="152.36276849642" height="160">' +
		    '</td>' +
		    '<td width="35%">' +
		    '<table width="100%">' +
		    '<tbody>' +
		    '<tr>' +
		    '<td>' +
		    '<table style="font-size:11px" width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td colspan="2" style="font-size:14px"><strong>iHotel</strong></td></tr><tr><td colspan="2" width="100%" valign="top">......................................<br>Thakor - 48000<br>Nakhon Phanom, Thailand</td></tr><tr><td width="10%"><strong>Phone:</strong></td><td width="90%">+6642543355</td></tr><tr><td><strong>Fax:</strong></td><td>+6642543377</td></tr><tr><td><strong>Email:</strong></td><td>ihotelthailands@gmail.com</td></tr><tr><td><strong>Website:&nbsp;</strong></td><td>www.ihotel.co.th</td></tr></tbody></table>' +
		    '</td>' +
		    '</tr>' +
		    '</tbody>' +
		    '</table>' +
		    '</td>' +
		    '</tr>' +
		    '</tbody>' +
		    '</table>';
	var message = '<table style="font-size:11px"  ><tr><td colspan="4" >'+objArray.message+'</td></tr></table>';
	var messageThank = '<table style="font-size:11px"  ><tr><td colspan="4" >'+objArray.thxmessage+'</td></tr></table>';
	var Comfort =   '<table class="comfortTable" border="0" align="center" width="100%">' +
					'<tr>' +
					'<td width = "15%" align="right"><span style="font-weight:bold;">Res ID:</span> '+reservation+'</td><td colspan="2" width="30%"></td>'+
					'<td width="20%" align="right"><span style="font-weight:bold;">Check-in:</span>'+formatDateIn+'</td>'+
					'<td width="20%" align="right"><span style="font-weight:bold;">Check-out:</span>'+formatDateTo+'</td>'+
					'<td width="11%"><span class="link">How to use?</span></td>'+
					'</tr></table>';
	var detail = '<table class="borderstatement" style="font-size:11px; margin:10 10 10 10;" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF" width="50%">' +
					'<tr>' +
					'<td colspan = "4"><span style="font-weight:bold;"><center>BOOKING DETAILS</center></span></td>'+
					'</tr>'+
					'<tr><td width="30%" colspan = "1"><span style="font-weight:bold;"><center>Guest Name:</center></span></td><td width="70%" align="left" colspan = "3"><span style="color:#0BA5F6;">'+nameGuest+'(<span style="color:red;">P'+idGuest+'</span>)</span></td></tr>'+
					'<tr><td width="15%"><span style="font-weight:bold;"><center>Address:</center></span></td><td width="45%" align="left">'+addressLine1Guest+addressLine2Guest+'</td><td width="15%"><span style="font-weight:bold;"><center>Phone:</center></span></td><td width="25%" align="left">'+phoneGuest+'</td></tr>'+
					'<tr><td colspan = "4">'+
					'<table style="font-size:11px" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF"  width="100%">'+
						'<tr><td width="25"><span style="font-weight:bold;"><center>Created On</center></span></td>'+
						'<td width="25%"><span style="font-weight:bold;"><center>Stay Details</center></span></td>'+
						'<td width="25%"><span style="font-weight:bold;"><center>Room(s)/Person(s)</center></span></td>'+
						'<td width="25%"><span style="font-weight:bold;"><center>Amount </center></span></td></tr>'+
						'<tr><td width="25" valign="top" style="padding-top:0;"><span><center>-</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>'+rooType+'('+roomName+')<br>'+formatDateIn+'-'+formatDateTo+'<br>'+priceRateName+'</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>Room(s)/'+sumPerson+'('+adultRoom+commaAdultChild+childRoom+')</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>'+Balance+'</center></span></td></tr>'+
					'</table>'+
					'</td></tr>'+
					''+
					'</table>';
	var dataStateMent = '<tr style="background-color:#CCCCCC;">' +
						'<td>'+dateDetailRoom+'</td>'+
						'<td>'+description+'</td>'+
						'<td colspan="6"></td>'+
						'</tr>';
	var stateMent = '<table  style="font-size:11px;" border="0" width="100%">'+
					'<tr>' +
					'<td colspan = "8"><span style="font-weight:bold;"><center>ACCOUNT STATEMENT</center></span></td>'+
					'</tr>'+
					'</table>'+
					'<table class="borderstatement" style="font-size:11px;"  border="0" bgcolor="#FFFFFF" width="100%">' +
					'<tr style="color:#ABABB4;"><td>Date</td><td>Description-References</td><td>Folio #</td><td>Disc/Allw</td><td>Charges</td><td>Tax</td><td align="right">Currency</td><td align="right">Payment</td></tr>'+
						dataStateMent+
						paymentPrint+
						chargePrint+
						textSumStatement+
					'</table>';
	var sumAmount = '<table  align="center" bgcolor="#FFFFFF" border="0" cellpadding="10" cellspacing="0" width="100%">' +
				    '<tbody>' +
				    '<tr>' +
				    '<td width="65%">' +
				    '</td>' +
				    '<td width="35%">' +
				    '<table width="100%">' +
				    '<tbody>' +
				    '<tr>' +
				    '<td>' +
				    	'<table style="font-size:11px;" width="100%" border="0" cellpadding="0" cellspacing="0"><tbody>'+
						    '<tr><td width="40%"><strong>Booking Total </strong></td><td width="60%" align="right">'+TotalBalance+'</td></tr>'+
						    '<tr><td width="40%"><strong>Other Charges </strong></td><td width="60%" align="right">'+otherCharge+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Tax </strong></td><td width="60%" align="right">'+roomsTax+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Disc/Allw </strong></td><td width="60%" align="right">'+roomdiscount+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total With Tax </strong></td><td width="60%" align="right">'+TotalWithTax+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Paid </strong></td><td width="60%" align="right">'+payprice+'</td></tr>'+
						    '<tr><td width="40%"><strong>Balance </strong></td><td width="60%" align="right">'+Balance+'</td></tr>'+
					    '</table>' +
					'</td>' +
				    '</tr>' +
				    '</tbody>' +
				    '</table>' +
				    '</td>' +
				    '</tr>' +
				    '</tbody>' +
				    '</table>';
	myWindow.document.write(headHtml+hotel+message+Comfort+detail+stateMent+sumAmount+messageThank+'<body>');
	myWindow.print();
	myWindow.focus();
}
//